package com.liy.framework.common.redis;

import org.springframework.data.redis.connection.lettuce.*;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.connection.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.annotation.*;
import org.springframework.data.redis.serializer.*;
import org.springframework.context.annotation.*;

@ComponentScan({ "com.das.framework.common.redis.config", "com.das.framework.common.redis.utils" })
public class RedisAutoConfiguration
{
    @Primary
    @Bean
    public RedisTemplate<String, Object> redisCacheTemplate(final LettuceConnectionFactory redisConnectionFactory) {
        final RedisTemplate<String, Object> template = (RedisTemplate<String, Object>)new RedisTemplate();
        template.setConnectionFactory((RedisConnectionFactory)redisConnectionFactory);
        final Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = (Jackson2JsonRedisSerializer<Object>)new Jackson2JsonRedisSerializer((Class)Object.class);
        final ObjectMapper om = new ObjectMapper();
        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
        jackson2JsonRedisSerializer.setObjectMapper(om);
        final StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
        template.setKeySerializer((RedisSerializer)stringRedisSerializer);
        template.setValueSerializer((RedisSerializer)jackson2JsonRedisSerializer);
        template.setHashKeySerializer((RedisSerializer)stringRedisSerializer);
        template.setHashValueSerializer((RedisSerializer)jackson2JsonRedisSerializer);
        template.afterPropertiesSet();
        return template;
    }
}
